#!/bin/make
#

#
# commands
#

RM = del /F /Q
AS = ca65
LD = ld65

#
# Flags
#

ASFLAGS = -t vic20 -g  -I . -I ..\prototype
LDFLAGS =  

#
# Sources
#

FE3TS_SOURCES = \
	fe3ts.asm \
	fe3util.asm \
	fe3tsmain.asm
FE3TS_OBJECTS = $(patsubst %.asm,%.o,$(FE3TS_SOURCES))

FE3RD_SOURCES = \
	fe3rd.asm \
	rdmain.asm \
	rdboot.asm \
	rdglobal.asm \
	rdmem.asm \
	rddir.asm \
	rdio.asm \
	rdcmd.asm \
	rdrel.asm \
	autostart.asm
FE3RD_OBJECTS = $(patsubst %.asm,%.o,$(FE3RD_SOURCES))

RELTEST_SOURCES = \
	reltest.asm
RELTEST_OBJECTS = $(patsubst %.asm,%.o,$(RELTEST_SOURCES))

TARGETS = fe3ts.prg fe3rd.prg reltest.prg

#
# targets
#

.PHONY : all clean install

all:	$(TARGETS)

install:

clean:
	$(RM) $(FE3TS_OBJECTS) $(FE3RD_OBJECTS) $(TARGETS) fe3util.d64 rdmain.bin rddrv.bin $(patsubst %.prg,%.map,$(TARGETS)) $(patsubst %.prg,%.lbl,$(TARGETS))

fe3ts.prg:		$(FE3TS_OBJECTS) 
	$(LD) $(LDFLAGS) -C vic20-3k.cfg -m $(patsubst %.prg,%.map,$@) -Ln $(patsubst %.prg,%.lbl,$@) -o $@ $^
	
fe3rd.prg:		$(FE3RD_OBJECTS) 
	$(LD) $(LDFLAGS) -C vic20-rd.cfg -m $(patsubst %.prg,%.map,$@) -Ln $(patsubst %.prg,%.lbl,$@) -o $@ $^

reltest.prg:	$(RELTEST_OBJECTS) 
	$(LD) $(LDFLAGS) -C vic20-8k+.cfg -m $(patsubst %.prg,%.map,$@) -Ln $(patsubst %.prg,%.lbl,$@) -o $@ $^

#
# Pattern rules
#

.SUFFIXES:
.SUFFIXES: .asm .o

%.o : %.asm
	$(AS) $(ASFLAGS) -o $@ $<
